package librus.cheeseChaser.tile
{
	import flash.geom.Rectangle;
	
	import starling.display.Image;
	import starling.events.Event;
	import starling.events.Touch;
	import starling.events.TouchEvent;
	import starling.events.TouchPhase;
	import starling.textures.Texture;
	
	import librus.cheeseChaser.util.Assets;
	import librus.cheeseChaser.util.Sprite;
	
	public class Tile extends Sprite
	{
		public function Tile(type:TileType)
		{
			super();
			__type = type;			
		}
		
		private var __type:TileType;
		private var front:Image;
		private var back:Image;
				
		private var __isPlaced:Boolean = false;;
						
		public function get type():TileType
		{
			return __type;
		}

		public function get isPlaced():Boolean
		{
			return __isPlaced;
		}

		public function set isPlaced(value:Boolean):void
		{
			__isPlaced = value;
		}

		override protected function startup():void
		{
			isListeningToResize = true;
			front = new Image(Assets.getAtlas().getTexture("tile_"+type.value));
			front.visible = false;
			addChild(front);
								
			back = new Image(Assets.getAtlas().getTexture("tile_back"));
			addChild(back);			
						
			onResize();
		}
		
		public function flip():void
		{
			front.visible = !front.visible;
			back.visible = !back.visible			
		}
		
		override protected function onResize():void
		{	
			front.height = back.height = front.width = back.width = Assets.TILE_SIZE;
			front.x = back.x = front.y = back.y = 0;			
		}
	}
}